package com.example.crowdfundingadminspringboot.controller;

import com.example.crowdfundingadminspringboot.common.ResultEntity;
import com.example.crowdfundingadminspringboot.pojo.Role;
import com.example.crowdfundingadminspringboot.service.RoleService;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/role")
public class RoleController {
	
	@Resource
	RoleService roleService;
	
	@ResponseBody
	@RequestMapping("/search/by/keyword")
	public ResultEntity<PageInfo<Role>> search(
			@RequestParam(value="pageNum", defaultValue="1",required = false) Integer pageNum,
			@RequestParam(value="pageSize", defaultValue="5",required = false) Integer pageSize,
			@RequestParam(value="keyword", defaultValue="",required = false) String keyword
	) {
		
		// 1.查询得到PageInfo对象
		PageInfo<Role> pageInfo = roleService.queryForKeywordWithPage(pageNum, pageSize, keyword);
		
		// 2.封装结果对象返回
		return ResultEntity.successWithoutData(pageInfo);
	}
}

